package com.example.myapplication.tack_30;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.myapplication.R;
import com.example.myapplication.tack_30.fragment.HomekFragment;
import com.example.myapplication.tack_30.fragment.OrderFragment;
import com.example.myapplication.tack_30.fragment.PersonFragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;

public class TakeawayActivity extends AppCompatActivity {
    private ImageView exit;
    private HomekFragment homekFragment;
    private OrderFragment orderFragment;
    private PersonFragment personFragment;
    private BottomNavigationView bottom;
    private LinearLayout main;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_30_activity_takeaway);
        init();
        initExit();
        getSupportFragmentManager().beginTransaction().replace(R.id.main,homekFragment).commit();
        bottom.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch(item.getItemId()){
                    case R.id.home:
                        getSupportFragmentManager().beginTransaction().replace(R.id.main,homekFragment).commit();
                        break;
                    case R.id.order:
                        getSupportFragmentManager().beginTransaction().replace(R.id.main,orderFragment).commit();
                        break;
                    case R.id.person:
                        getSupportFragmentManager().beginTransaction().replace(R.id.main,personFragment).commit();
                        break;
                }
                return true;
            }
        });
    }

    private void initExit() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TakeawayActivity.this.finish();
            }
        });
    }

    private void init() {
        homekFragment = new HomekFragment();
        orderFragment = new OrderFragment();
        personFragment = new PersonFragment();
        exit = findViewById(R.id.exit);
        main = findViewById(R.id.main);
        bottom = findViewById(R.id.bottom);
    }
}